package com.hongzhimei.yukicomic.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.flyco.tablayout.SlidingTabLayout;
import com.hongzhimei.yukicomic.R;
import com.hongzhimei.yukicomic.adapter.CommunityAdapter;


import com.hongzhimei.yukicomic.fragment.community.HotFragment;
import com.hongzhimei.yukicomic.fragment.community.followFragment;
import com.hongzhimei.yukicomic.fragment.community.newFragment;


import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * wuwei
 * 福利仓
 */

public class CommunityFrament extends BaseFragment {

    @Bind(R.id.fragment_community_addArticle)
    ImageView fragmentCommunityAddArticle;
    @Bind(R.id.fragment_community_viewpage)
    ViewPager fragmentCommunityViewpage;
    @Bind(R.id.fragment_community_tablayout)
    SlidingTabLayout fragmentCommunityTablayout;
    private String[] communityArrays;
    private HotFragment hotfragment;
    private newFragment newfragment;
    private followFragment followfragment;
    List<Fragment> mlist = new ArrayList<>();
    private CommunityAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }


    @Override
    public int getLayoutResId() {
        return R.layout.fragment_community;
    }

    @Override
    public void initView(View view) {
    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {
//获取标题
        communityArrays = getActivity().getResources().getStringArray(R.array.community);
        //设置tablayout和viewpage
        hotfragment = new HotFragment();
        newfragment = new newFragment();
        followfragment = new followFragment();
        mlist.add(hotfragment);
        mlist.add(newfragment);
        mlist.add(followfragment);

        //设置adapter以及标题
        adapter = new CommunityAdapter(mlist, communityArrays, getActivity().getSupportFragmentManager());
        fragmentCommunityViewpage.setAdapter(adapter);//给ViewPager设置适配器
        fragmentCommunityTablayout.setViewPager(fragmentCommunityViewpage);//将TabLayout和ViewPager关联起来。
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    //当 fragment不可见时执行改方法
    @Override
    public void onInvisible() {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
